package benny.ApkposStore.Adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import benny.ApkposStore.R;
import benny.ApkposStore.model.Zuoflist;
import benny.ApkposStore.utils.Rotate3dView;

public class cookselectAdapter extends BaseAdapter {

	private Context context;
	private List<Zuoflist> list;
	private LayoutInflater mInflater;
//	private TextPaint tp = null;

	public cookselectAdapter(Context context, List<Zuoflist> list) {
		this.context = context;
		this.list = list;
		mInflater = LayoutInflater.from(this.context);
	}

	public int getCount() {
		// TODO Auto-generated method stub
		if (list != null)
			return list.size();
		else
			return 0;
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		if (list != null)
			return list.get(position);
		else
			return null;
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@SuppressWarnings("unused")
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Cookselectholder cookselectholder = null;

		if (cookselectholder == null) {
		cookselectholder = new Cookselectholder();	
		convertView = mInflater.inflate(R.layout.cookselectitem, null);
		cookselectholder.cookitem1 = (TextView) convertView
				.findViewById(R.id.cookitem1);
		cookselectholder.cookitem2 = (TextView) convertView
				.findViewById(R.id.cookitem2);
		cookselectholder.cookitem3 = (TextView) convertView
				.findViewById(R.id.cookitem3);
		cookselectholder.cookitem4 = (Rotate3dView) convertView
				.findViewById(R.id.cookitem4);
		cookselectholder.cookitem5 = (Rotate3dView) convertView
				.findViewById(R.id.cookitem5);
		
		cookselectholder.cookitem4.setParentWidth(35);
		cookselectholder.cookitem4.setParentHeight(23);
		cookselectholder.cookitem4.setRotateImage(R.drawable.del2,R.drawable.del2);
		
		cookselectholder.cookitem5.setParentWidth(35);
		cookselectholder.cookitem5.setParentHeight(23);
		cookselectholder.cookitem5.setRotateImage(R.drawable.del1,R.drawable.del1);
		
		convertView.setTag(cookselectholder);
		}
		else {
			cookselectholder = (Cookselectholder)convertView.getTag();	
		}
//		addListener(convertView,position);
		cookselectholder.cookitem1.setText(list.get(position).getMingc());
		cookselectholder.SL= list.get(position).getSl();
		cookselectholder.DW= list.get(position).getDw();
		cookselectholder.ZUOF_ID= list.get(position).getZuof_id()+"";
		cookselectholder.JIAG= list.get(position).getJiag();
		cookselectholder.position=position;
		String sss = "";
		if (cookselectholder.SL>0.001) {
			sss=cookselectholder.SL+list.get(position).getDw();
		}
		else {
			sss=list.get(position).getDw();
		}
		if (!sss.equals("")) {
			cookselectholder.cookitem2.setText(sss);	
		}
		if (cookselectholder.JIAG>0) {
			cookselectholder.cookitem3.setText(cookselectholder.JIAG
					+"元");	
		}
	
		if (cookselectholder.SL>0.001) {
			cookselectholder.cookitem4.setVisibility(View.VISIBLE);	
		}
		else {
			cookselectholder.cookitem4.setVisibility(View.INVISIBLE);
		}
		



		
		return convertView;
	}

/*	public void addListener(View convertView,int arg) {
		final int arg2=arg;
		((Rotate3dView)convertView.findViewById(R.id.cookitem5)).setOnClickListener(
				new View.OnClickListener() {
					public void onClick(View v) {
						Toast.makeText(DishordersActivity.Activitythis, "点击了第"+arg2+"项",
								Toast.LENGTH_SHORT).show();
					
					}
				});
		((Rotate3dView)convertView.findViewById(R.id.cookitem4)).setOnClickListener(
				new View.OnClickListener() {

					public void onClick(View v) {
						if (DishordersActivity.dishcookwin != null) {
							DishordersActivity.dishcookwin.dismiss();
						}	
						
					}
				});
		
	}*/

	public final class Cookselectholder {
		public TextView cookitem1;
		public TextView cookitem2;
		public TextView cookitem3;
		public Rotate3dView  cookitem4;
		public Rotate3dView  cookitem5;
		public String  DW;
		public String  ZUOF_ID;
		public float  SL;
		public float  JIAG;
		public  int  position;
		

	}

	
}